package cn.spike.rockcc.service.impl;

import cn.spike.rockcc.domain.CourseChapter;
import cn.spike.rockcc.mapper.CourseChapterMapper;
import cn.spike.rockcc.service.ICourseChapterService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程章节 ， 一个课程，多个章节，一个章节，多个视频 服务实现类
 * </p>
 *
 * @author spike
 * @since 2023-03-11
 */
@Service
public class CourseChapterServiceImpl extends ServiceImpl<CourseChapterMapper, CourseChapter> implements ICourseChapterService {

    @Autowired
    private ICourseChapterService iCourseChapterService;

    @Override
    public boolean insert(CourseChapter entity) {
        Wrapper<CourseChapter> wrapper = new EntityWrapper<>();
        wrapper.eq("course_id",entity.getCourseId());
        List<CourseChapter> courseChapters = iCourseChapterService.selectList(wrapper);
        entity.setNumber(courseChapters.size()+1);
        return super.insert(entity);
    }
}
